=pod
      Trade Me API Wrapper
      Copyright (C) 2011 Trade Me
      Author Tim Wright http://www.trademe.co.nz

      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
      License as published by the Free Software Foundation; either
      version 2.1 of the License, or (at your option) any later version.

      This library is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Lesser General Public License for more details.

      You should have received a copy of the GNU Lesser General Public
      License along with this library; if not, write to the Free Software
      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
=cut

package TradeMeMember;

use strict;
use TradeMeApiWrapper;
use fields qw(wrapper);
use Data::Dumper;
use HTTP::Request::Common;

use constant MEMBER_PROFILE_URL => "http://api.trademe.co.nz/{version}/Member/{id}/Profile.{format}";
use constant MEMBER_FEEDBACK_URL => "http://api.trademe.co.nz/{version}/Member/{id}/Feedback.{format}";
use constant CUSTOM_MEMBER_FEEDBACK_URL => "http://api.trademe.co.nz/{version}/Member/{id}/Feedback/{filter}.{format}";
use constant MEMBER_FEEDBACK_COUNT_URL => "http://api.trademe.co.nz/{version}/Member/{id}/FeedbackCount.{format}";
use constant MEMBER_LISTINGS_URL => "http://api.trademe.co.nz/{version}/Member/{id}/Listings/All.{format}";
use constant MEMBER_ID_URL => "http://api.trademe.co.nz/{version}/Member/{nickname}.{format}";

sub new {
    my TradeMeMember $self = shift;
    my TradeMeApiWrapper $wrapper = shift;

    unless (ref $self) {
        $self = fields::new($self);
    }    
    
    $self->{'wrapper'} = $wrapper; 
    
    return $self;
}

sub getMemberProfileXML {
	my ($self, $id) = @_;
	
	my $url = MEMBER_PROFILE_URL;
	$url =~ s/{version}/v1/g; 
	$url =~ s/{id}/$id/g;
	$url =~ s/{format}/xml/g;
	
	return $self->{'wrapper'}->get($url);
}

sub getMemberProfileJSON {
	my ($self, $id) = @_;
	
	my $url = MEMBER_PROFILE_URL; 
	$url =~ s/{version}/v1/g;	
	$url =~ s/{id}/$id/g;
	$url =~ s/{format}/json/g;
	
	return $self->{'wrapper'}->get($url);
}

sub getMemberFeedbackXML {
	my ($self, $id) = @_;
	
	my $url = MEMBER_FEEDBACK_URL;
	$url =~ s/{version}/v1/g;	 
	$url =~ s/{id}/$id/g;
	$url =~ s/{format}/xml/g;
	
	return $self->{'wrapper'}->get($url);
}

sub getMemberFeedbackJSON {
	my ($self, $id) = @_;
	
	my $url = MEMBER_FEEDBACK_URL;
	$url =~ s/{version}/v1/g;	 
	$url =~ s/{id}/$id/g;
	$url =~ s/{format}/json/g;
	
	return $self->{'wrapper'}->get($url);
}

sub getAllMemberFeedbackXML {
	my ($self, $id) = @_;
	
	my $url = CUSTOM_MEMBER_FEEDBACK_URL;
	$url =~ s/{version}/v1/g;	 
	$url =~ s/{id}/$id/g;
	$url =~ s/{filter}/all/g;
	$url =~ s/{format}/xml/g;
	
	return $self->{'wrapper'}->get($url);
}

sub getAllMemberFeedbackJSON {
	my ($self, $id) = @_;
	
	my $url = CUSTOM_MEMBER_FEEDBACK_URL;
	$url =~ s/{version}/v1/g;
	$url =~ s/{id}/$id/g;
	$url =~ s/{format}/json/g;
	$url =~ s/{filter}/all/g;	
	
	return $self->{'wrapper'}->get($url);
}

sub getSellingMemberFeedbackXML {
	my ($self, $id) = @_;
	
	my $url = CUSTOM_MEMBER_FEEDBACK_URL; 
	$url =~ s/{version}/v1/g;
	$url =~ s/{id}/$id/g;
	$url =~ s/{format}/xml/g;
	$url =~ s/{filter}/selling/g;	
	
	return $self->{'wrapper'}->get($url);
}

sub getSellingMemberFeedbackJSON {
	my ($self, $id) = @_;
	
	my $url = CUSTOM_MEMBER_FEEDBACK_URL; 
	$url =~ s/{version}/v1/g;	
	$url =~ s/{id}/$id/g;
	$url =~ s/{format}/json/g;
	$url =~ s/{filter}/selling/g;	
	
	return $self->{'wrapper'}->get($url);
}

sub getBuyingMemberFeedbackXML {
	my ($self, $id) = @_;
	
	my $url = CUSTOM_MEMBER_FEEDBACK_URL;
	$url =~ s/{version}/v1/g;
	$url =~ s/{id}/$id/g;
	$url =~ s/{format}/xml/g;
	$url =~ s/{filter}/buying/g;	
	
	return $self->{'wrapper'}->get($url);
}

sub getBuyingMemberFeedbackJSON {
	my ($self, $id) = @_;
	
	my $url = CUSTOM_MEMBER_FEEDBACK_URL;
	$url =~ s/{version}/v1/g;	 
	$url =~ s/{id}/$id/g;
	$url =~ s/{format}/json/g;
	$url =~ s/{filter}/buying/g;	
	
	return $self->{'wrapper'}->get($url);
}

sub getMemberFeedbackCountXML {
	my ($self, $id) = @_;
	
	my $url = MEMBER_FEEDBACK_COUNT_URL;
	$url =~ s/{version}/v1/g;	 
	$url =~ s/{id}/$id/g;
	$url =~ s/{format}/xml/g;
	
	return $self->{'wrapper'}->get($url);
}

sub getMemberFeedbackCountJSON {
	my ($self, $id) = @_;
	
	my $url = MEMBER_FEEDBACK_COUNT_URL;
	$url =~ s/{version}/v1/g;	 
	$url =~ s/{id}/$id/g;
	$url =~ s/{format}/json/g;	
	
	return $self->{'wrapper'}->get($url);
}

sub getMemberListingsXML {
	my ($self, $id) = @_;
	
	my $url = MEMBER_LISTINGS_URL;
	$url =~ s/{version}/v1/g;	 
	$url =~ s/{id}/$id/g;
	$url =~ s/{format}/xml/g;
	
	return $self->{'wrapper'}->get($url);
}

sub getMemberListingsJSON {
	my ($self, $id) = @_;
	
	my $url = MEMBER_LISTINGS_URL;
	$url =~ s/{version}/v1/g;	 
	$url =~ s/{id}/$id/g;
	$url =~ s/{format}/json/g;	
	
	return $self->{'wrapper'}->get($url);
}

sub getMemberIdXML {
	my ($self, $nickname) = @_;
	
	my $url = MEMBER_ID_URL; 
	$url =~ s/{version}/v1/g;
	$url =~ s/{nickname}/$nickname/g;
	$url =~ s/{format}/xml/g;
	
	return $self->{'wrapper'}->get($url);
}

sub getMemberIdJSON {
	my ($self, $nickname) = @_;
	
	my $url = MEMBER_ID_URL;
	$url =~ s/{version}/v1/g;	 
	$url =~ s/{nickname}/$nickname/g;
	$url =~ s/{format}/json/g;	
	
	return $self->{'wrapper'}->get($url);
}

1;